package com.ruoyi.labmanage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.labmanage.domain.Labreservation;
import com.ruoyi.labmanage.service.ILabreservationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实验室预约Controller
 * 
 * @author lh
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/labreservation")
public class LabreservationController extends BaseController
{
    @Autowired
    private ILabreservationService labreservationService;

    /**
     * 查询实验室预约列表
     */
    @RequiresPermissions("labmanage:labreservation:list")
    @GetMapping("/list")
    public TableDataInfo list(Labreservation labreservation)
    {
        startPage();
        List<Labreservation> list = labreservationService.selectLabreservationList(labreservation);
        return getDataTable(list);
    }

    /**
     * 导出实验室预约列表
     */
    @RequiresPermissions("labmanage:labreservation:export")
    @Log(title = "实验室预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Labreservation labreservation)
    {
        List<Labreservation> list = labreservationService.selectLabreservationList(labreservation);
        ExcelUtil<Labreservation> util = new ExcelUtil<Labreservation>(Labreservation.class);
        util.exportExcel(response, list, "实验室预约数据");
    }

    /**
     * 获取实验室预约详细信息
     */
    @RequiresPermissions("labmanage:labreservation:query")
    @GetMapping(value = "/{reservationId}")
    public AjaxResult getInfo(@PathVariable("reservationId") Long reservationId)
    {
        return success(labreservationService.selectLabreservationByReservationId(reservationId));
    }

    /**
     * 新增实验室预约
     */
    @RequiresPermissions("labmanage:labreservation:add")
    @Log(title = "实验室预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Labreservation labreservation)
    {
        return toAjax(labreservationService.insertLabreservation(labreservation));
    }

    /**
     * 修改实验室预约
     */
    @RequiresPermissions("labmanage:labreservation:edit")
    @Log(title = "实验室预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Labreservation labreservation)
    {
        return toAjax(labreservationService.updateLabreservation(labreservation));
    }

    /**
     * 删除实验室预约
     */
    @RequiresPermissions("labmanage:labreservation:remove")
    @Log(title = "实验室预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reservationIds}")
    public AjaxResult remove(@PathVariable Long[] reservationIds)
    {
        return toAjax(labreservationService.deleteLabreservationByReservationIds(reservationIds));
    }
}
